package gui;

import java.util.ArrayList;

import javax.swing.JTable;
import javax.swing.event.ListSelectionListener;

import model.Lokation;

/**
 * @author Aske B. Vammen
 */
public class LokationTable extends JTable{
	public LokationTable(Lokation[] lokationer, ListSelectionListener lsl) {
			// initLoka: Indeholder de variabler som lokationerne, der skal ind i tabellen, indeholder.
		Object[][] initLoka = new Object[lokationer.length][3];
		for (int i = 0; i < initLoka.length; i++) {
			Lokation l = (Lokation)lokationer[i];
			
			initLoka[i][0] = l.getReolNummer();
			initLoka[i][1] = l.getRaekkeNummer();
			initLoka[i][2] = l.getKolonneNummer();
		}
			//De lokationer der skal ind i tabellen, i object-form.
		ArrayList<Lokation> rawData = new ArrayList<Lokation>(); 
		for (int i = 0; i < lokationer.length; i++) {
			rawData.add(lokationer[i]);
		}
		setModel(new NotCellEditableLokationDefaultTableModel(
				initLoka,
				new String[] {
					"Reol nr.", "R\u00E6kke nr.", "Kolonne nr."
				}, 
				rawData
			));
		setAutoCreateRowSorter(true);
		addListSelectionListenerToModel(lsl);
		getTableHeader().setReorderingAllowed(false);
		getTableHeader().setResizingAllowed(false);
	}

	public void addListSelectionListenerToModel(ListSelectionListener lsl) {
		getSelectionModel().addListSelectionListener(lsl);
	}
}
